<template>
  <div class="app-container">
    <div class="head_cover">
      <img :src="List.cover" />
    </div>
    <div class="p15 clearfix" style="background: #ffffff">
      <div class="class_head_title textoverflow2">{{ List.name }}</div>
      <div class="class_head_left">
        <div class="class_head_number">
          <i style="font-size: 12px; font-weight: 400">抢购价：¥</i>
          <i>{{ skuActive ? skuList[skuActive].price : List.price }}</i>
        </div>
        <div class="class_head_men">
          <van-icon :name="require('@/assets/images/xuexirenshu.png')" />
          <span>{{ List.has_sku }}人已学习</span>
        </div>
      </div>
    </div>

    <div class="skuclass">
      <div class="headline">
        <span class="h_left">
          <i class="ml5">班次属性</i>
        </span>
      </div>
      <ul>
        <li v-for="(item, index) in skuList" :key="index">
          <van-button
            @click="skuActive = index"
            round
            :class="skuActive == index ? 'action_button skuActive' : 'action_button'"
          >{{ item.name }}</van-button>
        </li>
      </ul>
    </div>

    <!-- <van-divider />

    <div>
      <div class="headline">
        <span class="h_left">
          <i class="ml5">课程评论（1条）</i>
        </span>
        <span class="h_right">
          <van-icon name="arrow" />
        </span>
      </div>
    </div>-->

    <van-tabs :swipe-threshold="1" v-model="active" sticky swipeable>
      <van-tab title="课程详情">
        <div v-html="List.content" class="mt10"></div>
      </van-tab>
      <van-tab title="课程目录">
        <div class="headline_three" v-for="(item, index) in stagesList" :key="index">
          <div class="headline_three_left" @click="toStageClass(item)">
            <div class="textoverflow1">
              <img :src="require('@/assets/images/shiping.png')" alt />
              <span class="name">{{ item.name }}</span>
            </div>

            <van-icon name="arrow" />
          </div>
        </div>
      </van-tab>
    </van-tabs>

    <div class="footer">
      <div class="class_head_right" @click="favClick(interactList.is_fav)">
        <img
          :src="
            interactList.is_fav == 1
              ? require('@/assets/images/shoucang1.png')
              : require('@/assets/images/shoucang.png')
          "
          alt
        />
        <div class="shouc">{{ interactList.is_fav == 1 ? '已收藏' : '收藏' }}</div>
      </div>

      <van-button type="primary" round @click="handlezhifu">立即购买</van-button>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant'
import { parseFav } from '@/utils/status/user'
// import { getGoodsDetails, favMine, commonShorturl } from '@/api/home/product-list'
import { getGoodsDetails, favMine } from '@/api/goods/pack'
export default {
  data() {
    return {
      queryParams: {
        goods_id: null
      },
      List: {},
      active: 0,
      skuActive: 0,
      skuList: [],
      stagesList: [],
      interactList: { is_sku_buys: [] },
      show: false,
      showShare: false,
      showFenXiang: false
    }
  },

  computed: {
    loginList() {
      return this.$store.getters.loginList
    },
    type() {
      return this.$store.getters.type
    },
    profileList() {
      return this.$store.getters.profileList
    },
    share_token() {
      return this.$store.getters.share_token
    }
  },

  mounted() {
    this.queryParams.goods_id = this.$route.query.id
    this.fetchList()
  },

  methods: {
    // 初始化数据
    fetchList() {
      getGoodsDetails(this.queryParams).then(res => {
        this.List = res.data
        this.skuList = res.data.sku
        this.stagesList = res.data.stages
        this.interactList = res.data.interact
      })
    },
    // 确认支付
    handlezhifu() {
      this.$set(this.List, 'path', '/pack-details')
      this.$set(this.List, 'query', this.$route.query)
      this.$set(this.List, 'sku_id', this.skuList[this.skuActive] ? this.skuList[this.skuActive].id : 0)
      this.$set(this.List, 'share_token', this.$route.query.token || '')
      this.$store.dispatch('home/setGoodsList', this.List)
      if (this.$route.query.isWatch) {
        this.$router.push({ path: '/watch-confirm-order' })
      } else {
        this.$router.push({ path: '/confirm-order' })
      }
    },
    // 收藏
    favClick(row) {
      const { action, result, actionTip } = parseFav(row)
      const data = {
        goods_id: this.queryParams.goods_id,
        action: action
      }
      favMine(data).then(res => {
        this.interactList.is_fav = result
        Toast({
          message: actionTip
        })
      })
    },
    // 阶段课详情
    toStageClass(row) {
      const data = {
        goods_id: this.$route.query.id,
        stage_id: row.id,
        sku_id: this.skuList[this.skuActive] ? this.skuList[this.skuActive].id : 0,
        is_buy: this.interactList.is_sku_buys,
        isWatch: this.$route.query.isWatch || 0
      }
      if (this.$route.query.isWatch) {
        this.$router.push({ path: '/watch-stage-class', query: data })
      } else {
        this.$router.push({ path: '/stage-class', query: data })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  padding-bottom: 85px;
}
::v-deep .van-divider::after,
.van-divider::before {
  // border-style: hidden;
  border-width: 8px 0 0;
  border-color: #f6f6f6;
}
.class_head_title {
  margin-top: 15px;
  font-size: 16px;
  font-weight: bold;
  color: #333333;
  line-height: 24px;
}
.class_head_left {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  padding-bottom: 10px;
  line-height: 30px;
  .class_head_number {
    display: inline-block;
    font-size: 20px;
    font-weight: 800;
    color: #11a8a4;
    // line-height: 30px;
  }
  .class_head_men {
    margin-left: 15px;
    font-size: 12px;
    color: #999999;
    .van-icon {
      font-size: 15px;
      margin-right: 4px;
      vertical-align: text-bottom;
    }
  }
}

.skuclass {
  margin-top: 5px;
  margin-bottom: 5px;
  padding-top: 20px;
  padding-bottom: 20px;
  background: #ffffff;
  ul {
    display: flex;
    margin-top: 10px;
  }
  .action_button {
    width: 90px;
    height: 30px;
    margin-left: 15px;
    line-height: 30px;
    // background: #f2f2f5;
    // border-radius: 17px;
  }
  .skuActive {
    color: #ffffff;
    background: #009697;
  }
}
.headline_three {
  position: relative;
  background: #ffffff;
  margin-bottom: 5px;
  .headline_three_left {
    width: 80%;
    padding: 0 15px;
    line-height: 45px;
    img {
      width: 14px;
      height: 13px;
    }
    .name {
      padding-left: 10px;
      font-size: 14px;
      font-weight: 600;
      color: #333333;
    }
    .van-icon {
      position: absolute;
      right: 15px;
      top: 22px;
    }
  }
}

.see_more {
  width: 125px;
  height: 44px;
  display: block;
  margin: auto;
  font-size: 15px;
  font-weight: 500;
  color: #009697;
  background: #ffffff;
  border: 1px solid #deeded;
}

.footer {
  box-sizing: border-box;
  position: fixed;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 80px;
  padding: 15px;
  background: #ffffff;
  box-shadow: 0px -1px 4px 0px rgba(66, 66, 66, 0.19);
  .class_head_right {
    padding-top: 2px;
    width: 45px;
    text-align: center;
    img {
      width: 20px;
      height: 20px;
    }
    .shouc {
      font-size: 14px;
      font-weight: 400;
      color: #666666;
      line-height: 14px;
    }
  }
  .van-button {
    width: 208px;
    height: 46px;
    background: #009697;
    border-color: #009697;
    font-size: 16px;
    font-weight: bold;
  }
}

.skuActive {
  color: #ffffff;
  background: #11a8a4;
}
.action_zhifu {
  display: block;
  width: 270px;
  height: 44px;
  margin: 0 auto 12px;
  background: #009697;
  border-radius: 22px;
  font-size: 16px;
  font-weight: 500;
  color: #fffefe;
}

::v-deep .wrapper {
  // display: flex;
  // align-items: center;
  // justify-content: center;
  height: 100%;
  h2 {
    margin-top: 6%;
    font-size: 20px;
    font-weight: 800;
    text-align: center;
    color: #ffffff;
    line-height: 18px;
  }
  .van-icon {
    display: table;
    margin: 10px auto;
  }
}

.block1_div {
  height: 80%;
  display: flex;
  align-items: center;
  justify-content: center;
  img {
    z-index: 99999;
  }
}

.block1 {
  display: block;
  width: 290px;
  height: 500px;
  border-radius: 10px;
  margin: auto;
}

.loading {
  height: 100%;
  text-align: center;
  padding-top: 40%;
}

.block {
  position: fixed;
  left: 9999px;
  width: 360px;
  height: 685px;
  margin: auto;
  text-align: center;
  border-radius: 10px;
  // background: url('../../../../assets/img/haibao.png');
  background-size: 100% 100%;
  .touxiang {
    display: inline-block;
    margin-top: 26px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
  }
  .name {
    margin-top: 5px;
    font-size: 18px;
    font-weight: bold;
    color: #ffffff;
    line-height: 28px;
  }
  .name1 {
    font-size: 16px;
    font-weight: 500;
    color: #ffffff;
    line-height: 16px;
  }
  .sanjiao {
    width: 19px;
    height: 16px;
    margin: 10px auto 0;
    // background: url('../../../../assets/img/haibao-3.png');
    background-size: 100% 100%;
  }
  .course {
    box-sizing: border-box;
    height: 440px;
    // padding: 10px;
    background: #ffffff;
    box-shadow: 0px 0px 13px 0px rgba(81, 17, 0, 0.13);
    border-radius: 10px;
    .img1 {
      margin-top: 10px;
      width: calc(100% - 20px);
      height: 200px;
      border-radius: 10px;
      overflow: hidden;
    }
    .title {
      padding: 0px 0px 6px 10px;
      text-align: left;
      font-size: 16px;
      font-weight: bold;
      color: #333333;
      line-height: 20px;
    }
    .jiage {
      padding-left: 10px;
      text-align: left;
      font-size: 20px;
      font-weight: 800;
      color: #ff0000;
      line-height: 26px;
    }
    .img2 {
      display: inline-block;
      margin: 6px auto 0;
      width: 80px;
      height: 80px;
    }
    .van-button {
      display: block;
      margin: 7px auto;
      height: 27px;
      font-size: 14px;
      font-weight: bold;
      color: #f77b0d;
      line-height: 13px;
      background: linear-gradient(7deg, #ffe5de, #fff0dd);
      .van-button__text {
        padding-bottom: 8px !important;
      }
    }
  }
  .logo-hengfu {
    width: 150px;
    height: 22px;
    margin: 17px auto;
    // background: url('../../../../assets/img/logo-hengfu.png');
    background-size: 100% 100%;
  }
}

.fenxiang-bgm {
  height: 40%;
  // background: url('../../../../assets/img/fenxiang-bgm.png');
  background-size: 100% 100%;
}

.z9999 {
  z-index: 9999 !important;
}
</style>
